package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.system.domain.ScriptPersonageInfo;
import com.ruoyi.system.service.IScriptPersonageInfoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;

/**
 * 剧本信息Controller
 *
 * @author ruoyi
 * @date 2021-08-19
 */
@RestController
@RequestMapping("/script")
public class ScriptPersonageInfoController extends BaseController
{
    @Autowired
    private IScriptPersonageInfoService scriptPersonageInfoService;

    /**
     * 查询剧本信息列表
     */
    @PreAuthorize(hasPermi = "system:info:list")
    @GetMapping("/list")
    public AjaxResult list(ScriptPersonageInfo scriptPersonageInfo)
    {
        List<ScriptPersonageInfo> list = scriptPersonageInfoService.selectScriptPersonageInfoList(scriptPersonageInfo);
        return AjaxResult.success(list);
    }

    /**
     * 导出剧本信息列表
     */
    @PreAuthorize(hasPermi = "system:info:export")
    @Log(title = "剧本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScriptPersonageInfo scriptPersonageInfo) throws IOException
    {
        List<ScriptPersonageInfo> list = scriptPersonageInfoService.selectScriptPersonageInfoList(scriptPersonageInfo);
        ExcelUtil<ScriptPersonageInfo> util = new ExcelUtil<ScriptPersonageInfo>(ScriptPersonageInfo.class);
        util.exportExcel(response, list, "剧本信息数据");
    }

    /**
     * 获取剧本信息详细信息
     */
    @PreAuthorize(hasPermi = "system:info:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(scriptPersonageInfoService.selectScriptPersonageInfoById(id));
    }

    /**
     * 新增剧本信息
     */
    @PreAuthorize(hasPermi = "system:info:add")
    @Log(title = "剧本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScriptPersonageInfo scriptPersonageInfo)
    {
        return toAjax(scriptPersonageInfoService.insertScriptPersonageInfo(scriptPersonageInfo));
    }

    /**
     * 修改剧本信息
     */
    @PreAuthorize(hasPermi = "system:info:edit")
    @Log(title = "剧本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScriptPersonageInfo scriptPersonageInfo)
    {
        return toAjax(scriptPersonageInfoService.updateScriptPersonageInfo(scriptPersonageInfo));
    }

    /**
     * 删除剧本信息
     */
    @PreAuthorize(hasPermi = "system:info:remove")
    @Log(title = "剧本信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scriptPersonageInfoService.deleteScriptPersonageInfoByIds(ids));
    }
}